Socket
Socket
Sign inDemoInstall

npm-logical-tree

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-logical-tree

Calculate 'logical' trees from a package.json + package-lock


Version published
Weekly downloads
112K
increased by6.53%
Maintainers
1
Weekly downloads
 
Created

What is npm-logical-tree?

The npm-logical-tree package is a utility for generating and manipulating logical trees of npm dependencies. It helps in understanding the structure and relationships of dependencies in a project.

What are npm-logical-tree's main functionalities?

Generate Logical Tree

This feature allows you to generate a logical tree from a package.json file. The logical tree represents the hierarchical structure of dependencies in a project.

const logicalTree = require('npm-logical-tree');
const packageJson = require('./package.json');
const tree = logicalTree(packageJson);
console.log(tree);

Traverse Logical Tree

This feature allows you to traverse the logical tree and perform operations on each node. In this example, it prints the name of each dependency in the tree.

const logicalTree = require('npm-logical-tree');
const packageJson = require('./package.json');
const tree = logicalTree(packageJson);
function traverseTree(node) {
  console.log(node.name);
  if (node.dependencies) {
    Object.values(node.dependencies).forEach(traverseTree);
  }
}
traverseTree(tree);

Filter Dependencies

This feature allows you to filter dependencies in the logical tree based on a predicate function. In this example, it prints the names of dependencies that start with 'express'.

const logicalTree = require('npm-logical-tree');
const packageJson = require('./package.json');
const tree = logicalTree(packageJson);
function filterDependencies(node, predicate) {
  if (predicate(node)) {
    console.log(node.name);
  }
  if (node.dependencies) {
    Object.values(node.dependencies).forEach(child => filterDependencies(child, predicate));
  }
}
filterDependencies(tree, node => node.name.startsWith('express'));

Other packages similar to npm-logical-tree

Keywords

FAQs

Package last updated on 19 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc